<?php

class MeetingNoteListPanel extends QPanel {
    // Local instance of the Meta DataGrid to list MeetingNotes
    public $dtgMeetingNotes;

    // Other public QControls in this panel
    public $btnCreateNew;
    public $pxyEdit;

    public $intMeetingId;

    // Callback Method Names
    protected $strCloseEditPanelMethod;

    public function __construct($objParentObject, $strCloseEditPanelMethod, $strControlId = null) {
        // Call the Parent
        try {
            parent::__construct($objParentObject, $strControlId);
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }

        $this->intMeetingId = $_SESSION['MeetingId'];
        // Record Method Callbacks
        $this->strCloseEditPanelMethod = $strCloseEditPanelMethod;

        // Setup the Template
        $this->Template = __DOCROOT__ . __MEETING__ . '/tpl/MeetingNoteListPanel.tpl.php';

        // Instantiate the Meta DataGrid
        $this->dtgMeetingNotes = new MeetingNoteDataGrid($this);

        // Style the DataGrid (if desired)
        $this->dtgMeetingNotes->CssClass = 'datagrid';
        $this->dtgMeetingNotes->AlternateRowStyle->CssClass = 'alternate';

        // Add Pagination (if desired)
        $this->dtgMeetingNotes->Paginator = new QPaginator($this->dtgMeetingNotes);
        $this->dtgMeetingNotes->ItemsPerPage = 8;

        // Use the MetaDataGrid functionality to add Columns for this datagrid

        $this->dtgMeetingNotes->AdditionalConditions = QQ::Equal(QQN::MeetingNote()->MeetingId, $this->intMeetingId) ;

        // Create the Other Columns (note that you can use strings for meeting_note's properties, or you
        // can traverse down QQN::meeting_note() to display fields that are down the hierarchy)
        // $this->dtgMeetingNotes->MetaAddColumn('Id');
        // $this->dtgMeetingNotes->MetaAddColumn('MeetingId');
        //$this->dtgMeetingNotes->MetaAddColumn('AttachmentId');
        $this->dtgMeetingNotes->MetaAddColumn('Date');
        $this->dtgMeetingNotes->MetaAddColumn('Subject');
        //$this->dtgMeetingNotes->MetaAddColumn('Notes');
          $this->dtgMeetingNotes->AddColumn(new QDataGridColumn('Notes', '<?= $_FORM->strTruncate($_ITEM->Notes,100) ?>'));
     

        $this->dtgMeetingNotes->AddRowAction(new QMouseOverEvent(), new QCssClassAction('selectedStyle'));
        $this->dtgMeetingNotes->AddRowAction(new QMouseOutEvent(), new QCssClassAction());

        $this->dtgMeetingNotes->RowActionParameterHtml = '<?= $_ITEM->Id ?>';
        $this->dtgMeetingNotes->AddRowAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyEdit_Click'));


        // Setup the Create New button
        $this->btnCreateNew = new QButton($this);
        $this->btnCreateNew->Text = QApplication::Translate('Create a New') . ' ' . QApplication::Translate('MeetingNote');
        $this->btnCreateNew->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCreateNew_Click'));
    }

    public function pxyEdit_Click($strFormId, $strControlId, $strParameter) {
        $strParameterArray = explode(',', $strParameter);
        //$objEditPanel = new MeetingNoteEditPanel($this, $this->strCloseEditPanelMethod, $strParameterArray[0]);
        
        $objEditPanel = new MeetingNoteEditPanel($this, "Close", $strParameterArray[0]);
        $this->objForm->SetEditPanel($objEditPanel, "pnlNoteEdit");


    }

    public function btnCreateNew_Click($strFormId, $strControlId, $strParameter) {
        $objEditPanel = new MeetingNoteEditPanel($this, "Close");
        $this->objForm->SetEditPanel($objEditPanel, "pnlNoteEdit");
    }
}
?>